﻿using System.Reflection;

namespace System.Data
{
    public static class DataRowExtensions
    {
        public static T CreateObject<T>(this DataRow dr)
            where T : class ,new()
        {
            var obj = new T();
            var dmnType = typeof(T);
            foreach (PropertyInfo pi in dmnType.GetProperties())
            {
                if (!dr.Table.Columns.Contains(pi.Name))
                    continue;
                if (dr[pi.Name] is DBNull)
                    continue;
                pi.SetValue(obj, dr[pi.Name], null);
            }
            return obj;
        }
    }
}